package com.empire.module.sporttery.service.football500hot;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500hot.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500hot.Football500HotDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500hot.Football500HotMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 热度分析明细 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500HotServiceImpl implements Football500HotService {

    @Resource
    private Football500HotMapper football500HotMapper;

    @Override
    public Integer createFootball500Hot(Football500HotSaveReqVO createReqVO) {
        // 插入
        Football500HotDO football500Hot = BeanUtils.toBean(createReqVO, Football500HotDO.class);
        football500HotMapper.insert(football500Hot);
        // 返回
        return football500Hot.getId();
    }

    @Override
    public void updateFootball500Hot(Football500HotSaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500HotExists(updateReqVO.getId());
        // 更新
        Football500HotDO updateObj = BeanUtils.toBean(updateReqVO, Football500HotDO.class);
        football500HotMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500Hot(Integer id) {
        // 校验存在
        validateFootball500HotExists(id);
        // 删除
        football500HotMapper.deleteById(id);
    }

    private void validateFootball500HotExists(Integer id) {
        if (football500HotMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_HOT_NOT_EXISTS);
        }
    }

    @Override
    public Football500HotDO getFootball500Hot(Integer id) {
        return football500HotMapper.selectById(id);
    }

    @Override
    public PageResult<Football500HotDO> getFootball500HotPage(Football500HotPageReqVO pageReqVO) {
        return football500HotMapper.selectPage(pageReqVO);
    }

}